/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.sun.courier.dal;

import com.sun.courier.entity.Administrator;
import com.sun.courier.entity.EmployeeLogin;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author HONG QUAN
 */
public class LoginDAL {
    DataAccessHelper dah = new DataAccessHelper();
    
    public ArrayList<EmployeeLogin> getLogin(String username){
        String strQuery = "Select * from EmployeeLogin where Username='"+username+"'";
        ArrayList<EmployeeLogin> lst = new ArrayList<>();
        try {
            ResultSet rs = dah.executeQuery(strQuery);
            while(rs.next() && rs!= null){
                EmployeeLogin e = new EmployeeLogin();
                e.setEmpId(rs.getInt("EmpId"));
                e.setPassword(rs.getString("Password"));
                lst.add(e);
            }
        } catch (Exception e) {
        }
        return lst;
    }
    
    public ArrayList<Administrator> getAdminLogin(String adUser){
        String strQuery = "Select * from Administrator where AdUser='"+adUser+"'";
        ArrayList<Administrator> lst = new ArrayList<>();
        try {
            ResultSet rs = dah.executeQuery(strQuery);
            while(rs.next() && rs!= null){
                Administrator ad = new Administrator();
                ad.setAdId(rs.getInt("AdId"));
                ad.setAdPass(rs.getString("AdPass"));
                ad.setRole(rs.getString("Role"));
                lst.add(ad);
            }
        } catch (Exception e) {
        }
        return lst;
    }
    
    public int getDepartmentRole(int empId){
        String strQuery = "Select Department.Role from Department join Employee on Department.DepId = Employee.DepId where EmpId = '"+empId+"'";
        int role = 0;
        try {
            ResultSet rs = dah.executeQuery(strQuery);
            while(rs.next()){
                role = rs.getInt("Role");
            }
        } catch (Exception e) {
        }
        return role;
    }
    
    public int getDepartmentRoleOfAdministrator(int adId){
        String strQuery = "Select Department.Role from Department join Administrator on Department.DepId = Administrator.DepId where AdId = '"+adId+"'";
        int role = 0;
        try {
            ResultSet rs = dah.executeQuery(strQuery);
            while(rs.next()){
                role = rs.getInt("Role");
            }
        } catch (Exception e) {
        }
        return role;
    }
}
